package com.java.zhuiyun.api.front_desk_user.controller;

import com.java.zhuiyun.api.front_desk_user.entity.FrontDeskUser;
import com.java.zhuiyun.api.front_desk_user.service.FrontDeskUserService;
import com.java.zhuiyun.api.member_manager.entity.MemberType;
import com.java.zhuiyun.common.response.CommonResult;
import com.java.zhuiyun.util.pageUtil.PageRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName FrontDeskUserController
 * @Description TODO 前台用户管理控制层
 * @Author wuwan
 * @Date 2023/8/14 20:19
 **/
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/FrontDeskUser")
public class FrontDeskUserController {

    @Autowired
    private FrontDeskUserService frontDeskUserService;

    /*
    * @Author wuwan
    * @Description 前台用户数据查询
    * @Date 2023/8/14 20:35
    * @Return
    * @param null
    */
    @GetMapping("/getFrontDeskUser")
    public CommonResult getFrontDeskUser(String frontDeskName, PageRequest pageRequest){
        CommonResult getFrontDeskUser = CommonResult.ok(frontDeskUserService.getFrontDeskUser(frontDeskName,pageRequest));
        return getFrontDeskUser;
    }
    /*
    * @Author wuwan
    * @Description 定时任务用户解封
    * @Date 2023/8/15 10:22
    * @Return
    * @param null
    */
    @Scheduled(cron = "01 00 00 * * ?")// 每天凌晨执行一次
    public void myTask() {
        CommonResult updateAccount = frontDeskUserService.updateAccount();
        System.out.println("方法执行" + updateAccount+"条");
    }
    /*
    * @Author wuwan
    * @Description 前台用户封禁
    * @Date 2023/8/15 10:35
    * @Return
    * @param null
    */
    @PostMapping("/updateFrontDeskUser")
    public CommonResult updateFrontDeskUser(Integer id,String day){
        CommonResult updateFrontDeskUser = frontDeskUserService.updateFrontDeskUser(id,day);
        return CommonResult.ok(updateFrontDeskUser);
    }
    /*
    * @Author wuwan
    * @Description 申诉手动解封
    * @Date 2023/8/15 11:15
    * @Return
    * @param null
    */
    @PostMapping("/updateAccountRelease")
    public CommonResult updateAccountRelease(Integer id) {
        CommonResult updateAccount = frontDeskUserService.updateAccountRelease(id);
        return CommonResult.ok(updateAccount);
    }

    /*
    * @Author wuwan
    * @Description 用户信息详细查看
    * @Date 2023/8/16 11:37
    * @Return
    * @param null
    */
    @GetMapping("/queryById")
    public CommonResult queryById(Integer id){
        CommonResult commonResult = frontDeskUserService.queryById(id);
        return CommonResult.ok(commonResult);
    }

    /*
    * @Author WX
    * @Description 查询个人信息
    * @Date 2023/8/31 9:00
    * @Return
    * @param id
    */
    @GetMapping("/selectUserbyId")
    public CommonResult selectUserbyId (Integer id){
        return  CommonResult.ok(frontDeskUserService.selectUserbyId(id));
    }

    /*
    * @Author WX
    * @Description 修改个人信息
    * @Date 2023/8/31 9:00
    * @Return
    * @param FrontDeskUser MultipartFile
    */
    @RequestMapping("/updateUserById")
    public CommonResult updateUserById (FrontDeskUser frontDeskUser,MultipartFile file) {
       return CommonResult.ok(frontDeskUserService.updateUserById(frontDeskUser,file));
    }

    /*
    * @Author WX
    * @Description 查询会员购买与普通购买的差价
    * @Date 2023/8/31 9:01
    * @Return
    * @param null
    */
    @GetMapping("/getUserMemberManager")
    public CommonResult getUserMemberManager(Integer id) {
        return CommonResult.ok(frontDeskUserService.getUserMemberManager(id));
    }

    /*
    * @Author WX
    * @Description 查询登录用户头像
    * @Date 2023/8/31 9:01
    * @Return
    * @param id
    */
    @GetMapping("/getFrontUserImg")
    public CommonResult getFrontUserImg(Integer id){
        return CommonResult.ok(frontDeskUserService.getFrontUserImg(id));
    }

    /*
    * @Author WX
    * @Description 修改邮箱
    * @Date 2023/9/1 9:44
    * @Return
    * @param null
    */
    @PostMapping("/updateUserByEmail")
    public CommonResult updateUserByEmail (@RequestBody FrontDeskUser frontDeskUser) {
        return frontDeskUserService.updateUserByEmail(frontDeskUser);
    }

    /*
     * @Author WX
     * @Description 修改手机号
     * @Date 2023/9/1 9:44
     * @Return
     * @param null
     */
    @PostMapping("/updateUserByPhone")
    public CommonResult updateUserByPhone (@RequestBody FrontDeskUser frontDeskUser) {
        return frontDeskUserService.updateUserByPhone(frontDeskUser);
    }
}
